import {post}       from '@/util/request'
import router       from '@/router'

export default {
  namespace:'statisticsSummary',
	namespaced:true,
  state:{
		isLoading:false,
		driverPageData:[],
    orgPageData:[],
    driverSumData:null,
    orgSumData:null
	},
  mutations:{
    changeLoading(state,v){
			state.isLoading = v;
		},
		changeDriverPageData(state,v){
			state.driverPageData = v;
		},
    changeDriverSumData(state,v){
			state.driverSumData = v;
		},
    changeOrgPageData(state,v){
      state.orgPageData = v;
    },
    changeOrgSumData(state,v){
      state.orgSumData = v;
    }
  },
  actions:{
    async init({commit}, data) {
      commit('changeLoading',true);

      let res = await post('/stat/total/driverStatList',data);
      commit('changeDriverPageData',res.data.data);
      let res2 = await post('/stat/total/orgStatList',data);
      commit('changeOrgPageData',res2.data.data);
      let res3 = await post('/stat/total/driverStatSum',data);
      commit('changeDriverSumData',res3.data.data);
      let res4 = await post('/stat/total/orgStatSum',data);
      commit('changeOrgSumData',res4.data.data);

      commit('changeLoading',false);
    },
    async reloadDriverPage({commit}, data) {
      commit('changeLoading',true);
      let res = await post('/stat/total/driverStatList',data);
      commit('changeDriverPageData',res.data.data);
      commit('changeLoading',false);
		},
    async reloadOrgPage({commit}, data) {
      commit('changeLoading',true);
      let res = await post('/stat/total/orgStatList',data);
      commit('changeOrgPageData',res.data.data);
      commit('changeLoading',false);
		},
    async reloadDriverData({commit}, data) {
      commit('changeLoading',true);
      let res = await post('/stat/total/driverStatList',data);
      commit('changeDriverPageData',res.data.data);
      let res3 = await post('/stat/total/driverStatSum',data);
      commit('changeDriverSumData',res3.data.data);

      commit('changeLoading',false);
		},
    async reloadOrgData({commit}, data) {
      commit('changeLoading',true);
      let res2 = await post('/stat/total/orgStatList',data);
      commit('changeOrgPageData',res2.data.data);
      let res4 = await post('/stat/total/orgStatSum',data);
      commit('changeOrgSumData',res4.data.data);
      commit('changeLoading',false);
		}
  },
  subscriptions({dispatch},router){
		//给路由加监听一旦进入module绑定的页面时dispatch初始化action
		router.afterEach((to,from)=>{

		})
	}
};
